package dk.rafaelcouto.PhoneTone_Extractor;

import java.io.*;
import android.app.*;
import android.content.*;

class Eula
{
    private static final String ASSET_EULA = "EULA";
    private static final String PREFERENCES_EULA = "eula";
    private static final String PREFERENCE_EULA_ACCEPTED = "eula.accepted";
    
    private static void accept(final SharedPreferences sharedPreferences) {
        sharedPreferences.edit().putBoolean("eula.accepted", true).commit();
    }
    
    private static void closeStream(final Closeable closeable) {
        if (closeable == null) {
            return;
        }
        try {
            closeable.close();
        }
        catch (IOException ex) {}
    }
    
    private static CharSequence readEula(final Activity activity) {
        Closeable closeable = null;
        while (true) {
            try {
                final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(activity.getAssets().open("EULA")));
                try {
                    final StringBuilder sb = new StringBuilder();
                    while (true) {
                        final String line = bufferedReader.readLine();
                        if (line == null) {
                            break;
                        }
                        sb.append(line).append('\n');
                    }
                    closeStream(bufferedReader);
                    return sb;
                }
                catch (IOException ex) {
                    final BufferedReader bufferedReader2 = bufferedReader;
                    closeStream(bufferedReader2); 
                    closeStream(closeable);
                    return ""; 
                }
                finally {
                    closeable = bufferedReader;
                }
            }
            catch (IOException ex2) {
                final BufferedReader bufferedReader2 = null;
                continue;
            } 
        }
    }
    
    private static void refuse(final Activity activity) {
        activity.finish();
    }
    
    static boolean show(final Activity paramActivity) {
    	final SharedPreferences localSharedPreferences = paramActivity.getSharedPreferences("eula", 0);
        if (!localSharedPreferences.getBoolean("eula.accepted", false))
        {
          AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramActivity);
          localBuilder.setTitle(R.string.eula_title);
          localBuilder.setCancelable(true);
          localBuilder.setPositiveButton(R.string.eula_accept, new DialogInterface.OnClickListener()
          {
            public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
            {
              Eula.accept(localSharedPreferences);
              if ((paramActivity instanceof Eula.OnEulaAgreedTo))
                ((Eula.OnEulaAgreedTo)paramActivity).onEulaAgreedTo();
            }
          });
          localBuilder.setNegativeButton(R.string.eula_title, new DialogInterface.OnClickListener()
          {
            public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
            {
              Eula.refuse(paramActivity);
            }
          });
          localBuilder.setOnCancelListener(new DialogInterface.OnCancelListener()
          {
            public void onCancel(DialogInterface paramAnonymousDialogInterface)
            {
              Eula.refuse(paramActivity);
            }
          });
          localBuilder.setMessage(readEula(paramActivity));
          localBuilder.create().show();
          return false;
        }
        return true;
    }
    
    interface OnEulaAgreedTo
    {
        void onEulaAgreedTo();
    }
}
